package org.example.util.tika;//package com.njwx.yq.util.tika;
//
//import org.apache.tika.exception.TikaException;
//import org.apache.tika.metadata.Metadata;
//import org.apache.tika.parser.AutoDetectParser;
//import org.apache.tika.parser.ParseContext;
//import org.apache.tika.sax.BodyContentHandler;
//import org.apache.tika.sax.ToXMLContentHandler;
//import org.xml.sax.ContentHandler;
//import org.xml.sax.SAXException;
//
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//
///**
// * @author dingcan
// * @since 2023-11-03 13:57
// */
//public class TikaUtil {
//    private final static AutoDetectParser AUTO_DETECT_PARSER = new AutoDetectParser();
//
//    public static String parseToPlainText(String filePath) throws IOException, TikaException, SAXException {
//        try (InputStream inputStream = new FileInputStream(filePath)) {
//            return parseToPlainText(inputStream, -1);
//        }
//    }
//
//    public static String parseToPlainText(String filePath, int maxStringLength) throws IOException, TikaException, SAXException {
//        try (InputStream inputStream = new FileInputStream(filePath)) {
//            return parseToPlainText(inputStream, maxStringLength);
//        }
//    }
//
//    public static String parseToPlainText(InputStream inputStream) throws IOException, TikaException, SAXException {
//        return parseToPlainText(inputStream, -1);
//    }
//
//    public static String parseToPlainText(InputStream inputStream, int maxStringLength) throws IOException, TikaException, SAXException {
//        ContentHandler handler = new BodyContentHandler(maxStringLength);
//        Metadata metadata = new Metadata();
//        AUTO_DETECT_PARSER.parse(inputStream, handler, metadata, new ParseContext());
//        return handler.toString();
//    }
//
//    public static String parseToHtml(InputStream inputStream) throws IOException, SAXException, TikaException {
//        ContentHandler handler = new ToXMLContentHandler();
//        Metadata metadata = new Metadata();
//        AUTO_DETECT_PARSER.parse(inputStream, handler, metadata);
//        return handler.toString();
//    }
//
//    public static String parseToHtml(String filePath) throws IOException, SAXException, TikaException {
//        try (InputStream inputStream = new FileInputStream(filePath)) {
//            return parseToHtml(inputStream);
//        }
//    }
//}
